package metamodel.parser;

/**
 * User: felix
 * Date: 20.06.2005
 */
public class PrefixClassResolver implements ClassResolver {
    final String[] prefixList;

    public PrefixClassResolver(String[] prefixList) {
        this.prefixList = prefixList;
    }

    public PrefixClassResolver(String prefix) {
        this.prefixList = new String[]{prefix};
    }

    public Class resolveClass(String name) {
        for (int i = 0; i < prefixList.length; i++) {
            String s = prefixList[i];
            try {
                return getClass().getClassLoader().loadClass(s+name);

            } catch (ClassNotFoundException e) {}
            try {
                return getClass().getClassLoader().loadClass(s+"."+name);
            } catch (ClassNotFoundException e) {}
        }
        throw new RuntimeException("Could not resolve classname '"+name+"'");
    }
}
